// pages/article/articleList/articleList.js
import getIn from '../../../sdk/utils/getIn';
import { API_ARTICLE_LIST } from "../../../sdk/business/url";
import { showSuccess, showFail } from '../../../utils/util';
import { ARTICLE_DETAIL } from "../../../utils/url";
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // showList:{
    //   type: Boolean,
    //   value: false
    // }
  },

  /**
   * 组件的初始数据
   */
  data: {
    articleList: [],
    showVideoModal: false,
    currentVideoUrl: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    show (id, cate_name) {
      this.fetchData(id);
      this.setData({ cate_name })
    },
    fetchData (id) {
      const params = { cate_id: id };
      wx.showLoading()
      this.setData({ loading: true });
      global.request(API_ARTICLE_LIST, params, (code, res) => {
        if (code = 'SUCCESS') {
          const articleList = getIn(res.data, ['list']);

          // 处理数据以适应双列布局
          this.setData({ articleList });
          wx.hideLoading()
        } else if (code == 'FAIL') {
          showFail(res.msg)
          wx.hideLoading()
        }
      });
    },
    //   const dataset = e.currentTarget.dataset;
    //   const id = dataset.id;
    //   const queryString = `id=${id}&cate_name=${this.data.cate_name}`;
    //   global.navigateHelper.navigateTo({ pathname: ARTICLE_DETAIL, queryString });
    // }

    // 显示视频弹窗
    showVideo (e) {
      const videoUrl = e.currentTarget.dataset.video;
      if (videoUrl) {
        this.setData({
          showVideoModal: true,
          currentVideoUrl: videoUrl
        });
      } else {
        wx.showToast({
          title: '该文章没有视频',
          icon: 'none'
        });
      }
    },

    // 关闭视频弹窗
    closeVideoModal () {
      this.setData({
        showVideoModal: false,
        currentVideoUrl: ''
      });
    },

    // 全屏变化事件处理
    onFullScreenChange (e) {
      console.log('全屏状态变化', e);
    }
  }
})
